<template>
	<view class="container">
		<view class="v-yhq-container">
			<view class="v-yhq-item" v-for="(item, index) in datas.YHQs">
				<view class="v-item-header">
					{{ formatDay(item.StatisticDay) }}
				</view>
				<view class="v-item-group">
					<view class="v-item-left">
						<image src="../../static/yhq-active.png" mode="aspectFit"></image>
					</view>
					<view class="v-item-right">
					<text class="v-item-account">{{ item.YHQJE }} </text>
					<text class="v-item-unit">元</text>
					
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="message" type="message" class="pop-msg">
			<uni-popup-message :type="msgType" :message="messageText" :duration="duration"></uni-popup-message>
		</uni-popup>
	</view>
</template>

<script>
	import {
		dateUtils,
		authTokenUtil,
		validLoginToken
	} from "../../common/util.js"
export default {
	data() {
		return {
			datas: {
				YHQs: [
					// {
					// 	StatisticDay: '2024-04-12',
					// 	YHQJE: 500,						
					// },
					// {
					// 	StatisticDay: '2024-04-11',
					// 	YHQJE: 500,						
					// },
					// {
					// 	StatisticDay: '2024-04-10',
					// 	YHQJE: 500,						
					// },
					// {
					// 	StatisticDay: '2024-04-09',
					// 	YHQJE: 300,	
					// },
					// {
					// 	StatisticDay: '2024-04-08',
					// 	YHQJE: 300,	
					// }
				]
			}
		};
	},
	methods: {
		formatDay: function (time) {
			// 创建一个新的Date对象
			const today = new Date(time);

			// 使用getDay()方法获取星期几的数字表示
			const dayIndex = today.getDay();

			// 创建一个数组，包含星期几的名称
			const daysOfWeek = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];

			// 根据dayIndex从数组中获取对应的星期名称
			const dayName = daysOfWeek[dayIndex];

			return `${time} ${dayName}`;
		},
		getCoupon: function () {
			console.log('getCoupon');
			let _this = this;
			//正式代码
			var authToken = authTokenUtil();
		
			uni.request({
				url: _this.sysInfo.BasePath + 'Coupon/GetCouponDatas',
				method: 'POST',
				data: null,
				header: {
					'content-type': 'application/json',
					Authorization: `${authToken}`
				},
				success: (res) => {
					if (res && res.data && res.data.Succeeded === true) {
						console.log(res);
						_this.datas.YHQs = res.data.Data;
					} else {
						_this.sysUtils.tip({
							sender: _this,
		
							title: '获取优惠券信息失败！',
							icon: 'error'
						});
					}
				},
				fail: () => {
					_this.sysUtils.tip({
						sender: _this,
						title: '获取优惠券信息失败！',
						icon: 'error'
					});
				},
				complete: () => {}
			});
		},
		init: function () {
			let _this = this;
			console.log('init');
			_this.getCoupon();
		}
	},
	onShow() {
		let _this = this;
		// _this.init();
	},
	created() {
		let _this = this;
		validLoginToken(null, () => {
			uni.reLaunch({
				url: "/pages/account/login"
			})
		})
		_this.init();
	}
};
</script>

<style>
.container {
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	/* background-color: #f0f0f0; */
	height: 100%;
}
.v-yhq-container {
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	padding: 20rpx;
	box-sizing: border-box;
}
.v-yhq-item {
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	background-color: #fff;
	border-radius: 10rpx;
	margin-bottom: 30rpx;
}
.v-item-header {
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: center;
	background-color: #fff;
	color: #333;
	font-size: 26rpx;
	font-weight: bold;
	padding: 20rpx;
	border-radius: 10rpx 10rpx 0 0;
	border-bottom:solid 1px #f0f0f0;
}

.v-item-group {
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: stretch;
	font-size: 26rpx;
	color: #333;
	height: 200rpx;
}
.v-item-left {
	display: flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	flex: 1;
}
.v-item-left image{
	height: 200rpx;
	width:200rpx;
}
.v-item-right {
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: stretch;
	flex: 2;
}
.v-item-account{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: flex-end;
	font-size:72rpx;
	font-weight:bold;
	flex:1.5;
	color:#c93a00ff;
}
.v-item-unit{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: flex-start;
	font-size:26rpx;
	flex:1;
	padding-left:20rpx;
	box-sizing: border-box;
	padding-top: 30rpx;
	color:#999;
	font-weight: bold;
}

</style>
